package it.unive.taw;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ShowUserAcces
 */
public class ShowUserAcces extends HttpServlet {
	Integer accessCount = new Integer(0);

	
	  public void doGet(HttpServletRequest request, HttpServletResponse response)
	              throws ServletException, IOException {
		  
	    response.setContentType("text/html");
	    PrintWriter out = response.getWriter();
	   
	    String heading;

	    if (accessCount == null) 
	    {
	      accessCount = new Integer(0);
	      heading = "Welcome Newcomer";
	    } else {
	      heading = "Welcome Back";
	      accessCount = new Integer(accessCount.intValue() + 1);
	    }
	    
	    out.println(("<HTML><HEAD><TITLE>Test HttpSession</TITLE></HEAD>" +
	                "<BODY>\n" +
	                "<H1 ALIGN=\"CENTER\">" + heading + "</H1>\n" +
	                "<H2>Information on Your Session:</H2>\n" +
	                "<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
	                "<TR BGCOLOR=\"#FFAD00\">\n" +
	                "  <TH>Info Type<TH>Value\n" +
	                "<TR>\n" +"  <TD>ID\n" +"  <TD>" + "\n" +
	                "<TR>\n" +"  <TD>Creation Time\n" +
	                "  <TD>" + "\n" +
	                "<TR>\n" +"  <TD>Time of Last Access\n" +
	                "  <TD>" + "\n" +
	                "<TR>\n" +"  <TD>Number of Previous Accesses\n" +"  <TD>" +
	                accessCount + "\n" + "</TABLE>\n" +"</BODY></HTML>"));
